class Solution {
    vector<vector<int>> ret;
    vector<int> path;
    int target;
public:
    vector<vector<int>> combinationSum(vector<int>& candidates, int _target) {
        target = _target;
        dfs(candidates, 0, 0);
        return ret;
    }
    void dfs(vector<int>& candidates, int pos, int sum) {

        if (sum == target) {
            ret.push_back(path);
            return;
        }

        if (sum >= target || pos > candidates.size())return;

        for (int i = pos; i < candidates.size(); i++) {
            path.push_back(candidates[i]);
            dfs(candidates, i, sum + candidates[i]);
            path.pop_back();

        }

    }
};